<template>
	<view class="flex-col group">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<view class="flex-col">
			<view class="flex-col section_1">
				<view class="flex-row group_1">
					<image src="/static/local/16403089342852645411.png" class="image_1" @click="pageBack" />
					<u-tabs-swiper ref="uTabs" active-color="#FF960C" :list="list" :current="current" height="88"
						@change="tabsChange" :is-scroll="false" :offset="[10,120]" style="flex: 1;">
					</u-tabs-swiper>
				</view>
			</view>
			<swiper duration="200" class="swiper-item-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<z-paging ref="paging" class="z_pag" v-model="comments" @query="getCommentToMe"
						:empty-view-fixed="true" :fixed="false" :hide-loading-more-when-no-more-by-limit="5">
						<view class="flex-col group_2" v-for="item in comments" @tap="checkDetail(item)">
							<view class="justify-between group_3">
								<view class="flex-row">
									<u-image
										:src="item.commenterInfo?item.commenterInfo.avatar:'/static/member/avatra.png'"
										shape="circle" :lazy-load="true" class="image_2" mode="aspectFill"></u-image>
									<view class="flex-col group_5">
										<view class="flex-row">
											<text
												class="text_2">{{item.commenterInfo?item.commenterInfo.nickname:'已注销'}}</text>
											<text class="text_3">评论了你的帖子</text>
										</view>
										<text class="text_4">{{item._add_time_str}}</text>
									</view>
								</view>
								<image src="/static/remote/59d50f245e774077b29cc12824c65db5.png" class="image_4" />
							</view>
						</view>
					</z-paging>
				</swiper-item>
				<swiper-item class="swiper-item">
					<z-paging ref="pagingT" class="z_pag" v-model="likes" @query="getLikeToMe" :empty-view-fixed="true"
						:fixed="false" :hide-loading-more-when-no-more-by-limit="5">
						<view class="flex-col group_2" v-for="item in likes">
							<view class="justify-between group_3">
								<view class="flex-row">
									<u-image
										:src="item.commenterInfo?item.commenterInfo.avatar:'/static/member/avatra.png'"
										shape="circle" :lazy-load="true" class="image_2" mode="aspectFill"></u-image>
									<view class="flex-col group_5">
										<view class="flex-row">
											<text
												class="text_2">{{item.commenterInfo?item.commenterInfo.nickname:'已注销'}}</text>
											<text class="text_3">赞了你的帖子</text>
										</view>
										<text class="text_4">{{item._add_time_str}}</text>
									</view>
								</view>
							</view>
						</view>
					</z-paging>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk; // vk依赖
	export default {
		data() {
			// 页面数据变量
			return {
				list: [
					{ name: '评论' },
					{ name: '点赞', count: 0 }
				],
				current: 0,
				swiperCurrent: 0,
				comments: [], // 评论列表
				likes: [], // 点赞列表
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.init(options)
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// 页面数据初始化函数
			init(options) {
				this.list[1].count = vk.getVuex('$app.likeBadge').like
				this.list[0].count = vk.getVuex('$app.likeBadge').talk
			},
			// 获取对我的回复
			getCommentToMe(pageNo, pageSize) {
				vk.callFunction({
					url: 'client/bbs/pub/getCommentToMe',
					title: '获取中...',
					data: { pageNo, pageSize, need_user_info: true },
					success(data) {
						that.$refs.paging.complete(data.rows)
					}
				});
			},
			getLikeToMe(pageNo, pageSize) {
				vk.callFunction({
					url: 'client/bbs/pub/getLikeToMe',
					title: '获取中...',
					data: { pageNo, pageSize, need_user_info: true },
					success(data) {
						that.$refs.pagingT.complete(data.rows)
					}
				});
			},
			pageBack() {
				this.clearBage()
				uni.navigateBack({ delta: 1 })
			},
			// 查看发布详情
			checkDetail(item) {
				this.clearBage()
				uni.vk.navigateTo('/pages/square/detail?id=' + item.aid);
			},
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			clearBage() {
				if (!vk.getVuex('$app.likeBadge')) return
				// 先清除本地缓存，优化显示效果
				vk.setVuex('$app.likeBadge', false)
				uni.hideTabBarRedDot({ index: 3 })
				that.list[0].count = 0
				that.list[1].count = 0
				// 通知后台已读
				vk.callFunction({
					url: 'client/angle-mark/kh/clearSquareList',
					data: { need_user_info: true },
					success: function(data) {}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.group {
		flex: 1 1 auto;
		overflow-y: auto;

		.section_1 {
			padding: 0 20rpx;
			background-color: rgb(255, 255, 255);
			box-shadow: 0px 6rpx 12rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 0px 0px 30rpx 30rpx;
			position: relative;

			.group_1 {
				align-items: center;

				.image_1 {
					width: 20rpx;
					height: 36rpx;
				}

				/deep/ .u-scroll-bar {
					bottom: 0 !important;
				}
			}
		}

		.swiper-item-box {
			height: calc(100vh - 100rpx);

			scroll-view {
				height: 100% !important;
			}
		}

		.group_2 {
			padding-left: 30rpx;
			position: relative;

			.group_3 {
				padding: 34rpx 0 33rpx;

				.group_5 {
					margin-left: 20rpx;
					font-size: 28rpx;

					.text_4 {
						margin-top: 10rpx;
						color: rgb(153, 153, 153);
						font-size: 24rpx;
						line-height: 29rpx;
						white-space: nowrap;
					}

					.text_2 {
						color: rgb(255, 150, 12);
						line-height: 38rpx;
						white-space: nowrap;
						margin-right: 4rpx;
					}

					.text_3 {
						color: rgb(51, 51, 51);
						line-height: 38rpx;
						white-space: nowrap;
					}
				}
			}

			.image_6 {
				align-self: flex-end;
				width: 624rpx;
				height: 3rpx;
			}

			.top-group {
				padding: 32rpx 0 33rpx;

				.right-group {
					margin-left: 20rpx;

					.group_9 {
						padding-top: 2rpx;
						position: relative;

						.text_8 {
							position: absolute;
							right: 0;
							top: 0;
						}
					}

					.text_9 {
						margin-top: 6rpx;
						color: rgb(153, 153, 153);
						font-size: 24rpx;
						line-height: 29rpx;
						white-space: nowrap;
					}

					.text_10 {
						margin-top: 4rpx;
					}

					.text_5 {
						color: rgb(255, 150, 12);
						font-size: 32rpx;
						line-height: 38rpx;
						white-space: nowrap;
					}

					.text_7 {
						color: rgb(51, 51, 51);
						font-size: 32rpx;
						line-height: 38rpx;
						white-space: nowrap;
					}
				}

				.view_1 {
					width: 352rpx;
				}
			}

			.image_4 {
				margin-right: 20rpx;
				align-self: center;
				width: 16rpx;
				height: 28rpx;
			}

			.image_2 {
				width: 76rpx !important;
				height: 76rpx !important;
			}
		}

		.group_2::after {
			content: '';
			position: absolute;
			width: calc(100% - 126rpx);
			right: 0;
			bottom: 0;
			border-bottom: 1px solid #F0F0F0;
		}
	}

	/deep/ .u-badge {
		color: #fa3534 !important;
		top: 16rpx !important;
		right: 124rpx !important;
		width: 20rpx !important;
		height: 20rpx !important;
	}
</style>
